package com.ly.credit.controller;

import com.ly.credit.entity.User;
import com.ly.credit.service.ApiService;
import com.ly.credit.util.AdResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class IndexController {
	@Resource
	private HttpServletRequest request;
	@Resource
	private ApiService apiService;
	@RequestMapping("/manager/index.do")
	public String index(ModelMap map){
		HttpSession session = request.getSession();
		User user =(User) session.getAttribute("user");
		if(user==null){
			return "login";
		}
		AdResult apiList = apiService.getAll();
		map.put("user",user);
		map.put("apiList",apiList);
		return "views/index";
	}
	@RequestMapping("/manager/apiList.do")
	public String apiList(ModelMap map){
		AdResult apiList = apiService.getAll();
		if(apiList.getStatus()==2){
			return "login";
		}
		HttpSession session = request.getSession();
		User user =(User) session.getAttribute("user");
		user.setPhone(user.getPhone().replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2"));
		map.put("apiList",apiList);
		map.put("user",user);
		return "views/apiList";
	}
}
